package edu.ues21.tcs.ecommerce2011.mvc.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import edu.ues21.tcs.ecommerce2011.mvc.dao.UsuarioDAO;

/**
 * 
 * @author fmantaras.
 */
public class DeleteUsuarioController extends HttpServlet {

	private static final long serialVersionUID = 1L;

	ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
			"/BeanLocations.xml");

	UsuarioDAO uDao = (UsuarioDAO) appContext.getBean("usuarioDAO");

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String nombreUsuario = request.getParameter("nombreUsuario");
	
		if (nombreUsuario != null) {
			
			uDao.delete(nombreUsuario);

		}
		response.sendRedirect("CRUDUsuario.do");
	}

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		processRequest(request, response);

	}

	@Override
	public String getServletInfo() {
		return "Short description";
	}// </editor-fold>

}
